package com.best.controller;

import com.best.rpc.GatewayRpc;
import com.best.rpc.ProductRpc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jiang Akang
 * employeeId: BG435424
 * @date 2020/10/15
 **/
@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Value("${spring.application.name}")
    private String serverName;

    @Value("${server.port}")
    private String serverPort;

    @Value("${spring.cloud.nacos.discovery.metadata.version}")
    private String version;

    @Autowired
    private GatewayRpc gatewayRpc;

    @Autowired
    private ProductRpc productRpc;

    @GetMapping("/product")
    public String getProduct() {

        String consumer = "application name is: 【" + serverName + "】, server port is: 【" + serverPort + "】" + ", version is: 【" + version + "】";

        return  consumer  + " || " + productRpc.getApplicationInfo();
    }

    @GetMapping("/gateway")
    public String getGateway() {

        String consumer = "application name is: 【" + serverName + "】, server port is: 【" + serverPort + "】" + ", version is: 【" + version + "】";

        return  consumer  + " || " + gatewayRpc.getApplicationInfo();
    }
}
